package common.autoreview

import utils.LogUtil
import java.io.File
import java.util.concurrent.LinkedBlockingQueue
import java.util.concurrent.ThreadPoolExecutor
import java.util.concurrent.TimeUnit

object AutoReview {

    val TAG = AutoReview::class.simpleName!!

    private val executor: ThreadPoolExecutor by lazy {
        ThreadPoolExecutor(4, 20,
                600, TimeUnit.SECONDS,
                LinkedBlockingQueue())
    }
    private var inited = false

    fun init(){
        println(executor)
        inited = true
    }

    fun checkImagesAsync(files: List<File>, callback: (AutoReviewState) -> Unit){
        if (!inited) throw IllegalAccessException("AutoReview doesn't init, please invoke init() before")
        executor.execute {
            LogUtil.i(TAG, "checkImagesAsync start")
            val result = ContentSafeDetector.detectImages(files)
            LogUtil.i(TAG, "checkImagesAsync result: ${result.name}")
            callback(result)
        }
    }

    fun close(){
        executor.shutdown()
    }
}

object AutoReviewConfig{
    const val TERROR_PASS_THRESHOLD = 0.6
    const val TERROR_UNPASS_THRESHOLD = 0.6

    const val NROP_PASS_THRESHOLD = 0.6
    const val NROP_UNPASS_THRESHOLD = 0.6
}

enum class AutoReviewState{
    PASS, UNPASS, REVIEW
}